<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>春节返安人员申报</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
</head>
<style>
    * {
        background: #FFF8F5;
    }

    .layui-text {
        background: #F7771B;
        line-height: 16px;
        color: #FFF7F1;
        font-weight: bolder;
        font-size: 16px;
    }

    .layui-form-select dl dd.layui-this {
        background-color: #F7771B;
        color: #FFF7F1;
    }

    .layui-laydate .layui-this {
        background-color: #F7771B !important;
        color: #FFF7F1 !important;
    }

    .layui-form-select .layui-edge {
        right: 30px;
    }

    .layui-input,
    .layui-textarea {
        width: 90%;
        background: #FFF7F1;
        border-color: #FFF7F1;
        border-radius: 4px;
        box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0.2);
    }

    .layui-form-item .layui-input-inline {
        margin: 0 0 10px 126px;
    }

    .layui-form-item .layui-form-label {
        text-overflow: clip;
    }

    .input-code {
        width: 55%;
        display: inline;
    }

    #send_phone {
        padding: 0;
        width: 35%;
        float: right;
        margin-right: 15px;
        font-size: 12px;
    }

    .footer {
        text-align: center;
        font-size: 12px;
        color: #666666;
        position: fixed;
        bottom: 0;
        width: 100%;
    }

    .footer p {
        margin: 5px 0;
    }

    .layui-elem-quote {
        text-align: center;
        border-left: none;
    }

    .layui-form-radio>i:hover,
    .layui-form-radioed>i {
        color: #F7771B;
    }


    .layui-btn {
        background-color: #F7771B;
        box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0.2);
        margin-top: 10px;
    }

    .tishi {
        text-align: center;
        color: #666;
        font-size: 14px;
        margin-top: 10px;
        margin-bottom: 10px;
    }

    .layui-form-label {
        padding: 9px 9px 9px 0;
    }

    .layui-input-block {
        margin-left: 120px;
    }

    #launch-btn {
        width: 240px;
        padding-left: 60px;
        background: #fff;
    }

    .b {
        background-color: #cbcbcb;
    }

    .htmls {
        min-height: 480px;
    }

    .user_asset {
        margin-left: 20px;
        margin: 10px 0 10px 20px;
    }

    .no_img {
        width: 16px;
    }
  .layui-form-radio{
        margin: 6px 6px 0 0;
    }
</style>

<body>
    <blockquote class="layui-elem-quote layui-text">
        为了您和家人的健康请如实填写以下内容
    </blockquote>

    <form class="layui-form" action="">
        <div class="htmls">
            <input type="hidden" name="code" class="_wxcode">
            <input type="hidden" name="county" value="安平县">
            <div class="layui-form-item layui-form-name">
                <label class="layui-form-label">姓名*</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" lay-reqtext="请输入姓名" autocomplete="off"
                        placeholder="请输入姓名" class="layui-input layui_name">
                </div>
            </div>

            <div class="layui-form-item layui-form-idCard">
                <label class="layui-form-label">身份证号码*</label>
                <div class="layui-input-block">
                    <input type="text" name="idCard" lay-verify="identity" placeholder="请输入身份证号码" autocomplete="off"
                        class="layui-input layui_idCard">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">职业*</label>
                <div class="layui-input-block">
                    <select name="job" lay-verify="required" lay-reqtext="请选择职业">
                        <option value="">请选择职业</option>
                        <option value="0">学生</option>
                        <option value="1">公职人员</option>
                        <option value="2">农民工</option>
                        <option value="3">办企业</option>
                        <option value="4">开店铺</option>
                        <option value="5">其他</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-form-phone">
                <label class="layui-form-label">联系方式*</label>
                <div class="layui-input-block">
                    <input type="number" name="phone" lay-reqtext="请输入手机号" id="L_phone"
                        lay-verify="phone" placeholder="请输入手机号" autocomplete="off" class="layui-input layui_phone">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">在省、市外居住地*</label>
                <div class="layui-input-block">
                    <input type="text" name="outsideAddress" lay-verify="required" lay-reqtext="请输入在省、市外居住地"
                        placeholder="请输入在省、市外居住地" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">返乡时间*</label>
                <div class="layui-input-block">
                    <input type="text" name="returnDate" lay-verify="required" lay-reqtext="请选择返乡时间"
                        placeholder="请选择返乡时间" autocomplete="off" class="layui-input layui-dates" id="test1">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">来安方式*</label>
                <div class="layui-input-block">
                    <input type="radio" name="transport" lay-filter="transport" value="0" title="航班" checked>
                    <input type="radio" name="transport" lay-filter="transport" value="1" title="火车/高铁">
                    <input type="radio" name="transport" lay-filter="transport" value="2" title="客运">
                    <input type="radio" name="transport" lay-filter="transport" value="3" title="自驾">
                    <input type="radio" name="transport" lay-filter="transport" value="4" title="其它">
                </div>
            </div>
            <div class="layui-form-item layui-form-air">
                <div class="layui-input-block">
                    <input type="text" name="transportValue" lay-reqtext="请输入航班/列车车次/车牌号"  lay-verify="required"
                        placeholder="请输入航班/列车车次/车牌号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">在安居住地*</label>
                <div class="layui-input-block">
                    <select name="village" lay-verify="required" lay-reqtext="请选择在安居住地">
                        <option value="">请选择</option>
                        <option value="社区">城区</option>
                        <option value="安平镇">安平镇</option>
                        <option value="马店镇">马店镇</option>
                        <option value="南王庄镇">南王庄镇</option>
                        <option value="子文镇">子文镇</option>
                        <option value="东黄城镇">东黄城镇</option>
                        <option value="何庄乡">何庄乡</option>
                        <option value="油子乡">油子乡</option>
                        <option value="两洼乡">两洼乡</option>
                        <option value="高新区">高新区</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">详细地址*</label>
                <div class="layui-input-block">
                    <input type="text" name="address" lay-verify="required" lay-reqtext="请输入详细地址" placeholder="请输入详细地址"
                        autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">户籍地*</label>
                <div class="layui-input-block">
                    <input type="text" name="registeredAddress" lay-verify="required" lay-reqtext="请输入户籍地" placeholder="请输入户籍地(身份证地址)" 
                        autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">最近核酸检测时间*</label>
                <div class="layui-input-block">
                    <input type="text" name="lastTestDate" lay-verify="required" lay-reqtext="请选择最近核酸检测时间"
                        placeholder="请选择最近核酸检测时间" autocomplete="off" class="layui-input layui-dates" id="test2">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">检测结果*</label>
                <div class="layui-input-block">
                    <input type="radio" name="lastTestResult" value="0" title="阴性" checked>
                    <input type="radio" name="lastTestResult" value="1" title="阳性">
                </div>
            </div>
            <div class="user_asset">
                <img src="./images/no.png" alt="" onclick="asset()" class="no_img">
                <span onclick="window.location.href='http://hesuan.city1000.cn/users.html'">我已阅读并同意（用户许可协议）</span>
            </div>
            <div class="layui-form-item" style="text-align: center;">
                <button type="submit" class="layui-btn layui-date" lay-submit="" lay-filter="demo1"
                    style="width: 200px;">登记申报</button>
            </div>
        </div>
        

    </form>

    <script src="./layui/layui.js" charset="utf-8"></script>
    <script src="./jquery/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/fastclick/1.0.6/fastclick.min.js"></script>
    <script src="./api/api.js?v=01"></script>
    <script>
        // 用户许可协议
        function asset() {
            if ($('.no_img').attr('src') == './images/no.png') {
                $('.no_img').attr('src', './images/yes.png')
            } else {
                $('.no_img').attr('src', './images/no.png')
            }
        }
        layui.use(['form', 'layer', 'jquery', 'laydate'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.jquery,
                // layarea = layui.layarea,
                laydate = layui.laydate;
            //执行一个laydate实例
            $('.layui-dates').each(function () {
                console.log(this)
                laydate.render({
                    elem: this,
                  trigger : 'click'
                });
            });
            // layarea.render({
            //     elem: '#area-picker',
            //     data: {
            //         city: '深圳市',
            //         county: '龙岗区',
            //     },
            //     change: function (res) {
            //         //选择结果
            //         console.log(res);
            //     }
            // });
            // 这个页面用户没注册时进入的
            // 上一个页面带过来了code(用转发做的)和码上的id和中文名称
            var code = getQueryVariable('code')
            $(document).ready(function () {
                // 防止按钮延迟
                FastClick.attach(document.body);
                $("._wxcode").val(code)
            })
            console.log(code)
            //自定义验证规则
            form.verify({
                phone: [/^1[3456789]\d{9}$/, "请输入正确的手机号"],
                identity: [/(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"],
                code: function (value) {
                    if (!value || isNaN(value)) return "请填写正确的验证码"
                }
            });
            //监听提交
            form.on('submit(demo1)', function (data) {
                // 先判断姓名是不是数字,如果是数字,就返回
                var reg = /^[\u4e00-\u9fa5]+$/;
                if (!reg.test($('.layui_name').val())) {
                    layer.msg('姓名不正确', {
                        icon: 2
                    });
                    return false
                }
                console.log(data)
                if ($('.no_img').attr('src') == "./images/no.png") {
                    //console.log("用户协议未勾选")
                    layer.msg('请勾选用户许可协议', {
                        icon: 2
                    });
                    return false
                }
                console.log('data')
                console.log(data)
                var loadIndex;
                $.ajax({
                    url: `http://39.99.164.177:8082/api/insert?code=${code}&name=${data.field.name}&idCard=${data.field.idCard}&job=${data.field.job}&phone=${data.field.phone}&outsideAddress=${data.field.outsideAddress}&returnDate=${data.field.returnDate}&transport=${data.field.transport}&transportValue=${data.field.transportValue}&county=${data.field.county}&village=${data.field.village}&address=${data.field.address}&registeredAddress=${data.field.registeredAddress}&lastTestDate=${data.field.lastTestDate}&lastTestResult=${data.field.lastTestResult}`,
                    beforeSend: function () {
                        // 点击后阴影效果
                        loadIndex = layer.load(1, {
                            shade: [0.3, 'rgb(0, 0, 0)']
                        })
                    },
                    success: function (res) {
                        // 成功
                        console.log(res)
                        if (res.code == 0) {
                            layer.msg('登记成功', {
                                icon: 1,
                                time: 2000
                            });
                            // 登记成功后,跳转查询结果
                            window.location.href = encodeURI(
                                'http://user.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url=http://hesuan.city1000.cn/enterAp/lookfor.html&data=123'
                            )
                        } else {
                            // 失败
                            // alert("重新登记")
                            layer.confirm(res.msg, {
                                title: '系统提示'
                            }, function (index) {
                                window.location.href = encodeURI(
                                'http://user.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url=http://hesuan.city1000.cn/enterAp/register.html&data=123'
                            )
                            });
                        }
                    },
                    error: function (err) {
                        console.log(err)
                        layer.msg('系统维护更新中，请稍后...', {
                            icon: 2
                        });
                    },
                    complete: function () {
                        layer.close(loadIndex);
                    }
                });
                return false;
            });
        });
        // 获取code
        function getQueryVariable(variable) {
            // 参数 window.location.search
            var query = decodeURI(window.location.search.substring(1));
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            }
            return (false);
        }
        // 转发刷新code
        function getCode(urls, _data) {
            $.ajax({
                type: "get",
                url: "http://user.city1000.top/wechat/wxScan", //自己填写请求地址
                data: {
                    url: window.location.href
                },
                success: function (result) {
                    //alert(result.appId)
                    var appID = result.appId
                    var redirectUri = encodeURI(urls); // 授权成功后重定向地址
                    var state = _data; // 状态标识（用于项目拓展)
                    // 跳转授权(拿到用户信息)
                    var strUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
                        appID +
                        "&redirect_uri=" + redirectUri +
                        "&response_type=code&scope=snsapi_base&state=" + state +
                        "#wechat_redirect";
                    window.location.href = strUrl;
                }
            })
        }
    </script>

</body>

</html>